<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.10.0"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>l8w8jwt: include/l8w8jwt/base64.h File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<script type="text/javascript" src="clipboard.js"></script>
<script type="text/javascript" src="cookie.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="doxygen-awesome.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectalign">
   <div id="projectname">l8w8jwt
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.10.0 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_d44c64559bbebec7f509842c48db8b23.html">include</a></li><li class="navelem"><a class="el" href="dir_4cc40c4817b6dd8b994fc53e2126ebc6.html">l8w8jwt</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle"><div class="title">base64.h File Reference</div></div>
</div><!--header-->
<div class="contents">

<p>Base-64 encode and decode strings/bytes.  
<a href="#details">More...</a></p>
<div class="textblock"><code>#include &quot;<a class="el" href="version_8h_source.html">version.h</a>&quot;</code><br />
<code>#include &lt;stdint.h&gt;</code><br />
<code>#include &lt;string.h&gt;</code><br />
</div><div class="textblock"><div class="dynheader">
Include dependency graph for base64.h:</div>
<div class="dyncontent">
<div class="center"><img src="base64_8h__incl.png" border="0" usemap="#ainclude_2l8w8jwt_2base64_8h" alt=""/></div>
<map name="ainclude_2l8w8jwt_2base64_8h" id="ainclude_2l8w8jwt_2base64_8h">
<area shape="rect" title="Base&#45;64 encode and decode strings/bytes." alt="" coords="51,5,216,32"/>
<area shape="rect" href="version_8h.html" title="l8w8jwt version checking." alt="" coords="5,80,78,107"/>
<area shape="poly" title=" " alt="" coords="119,35,71,73,67,68,116,30"/>
<area shape="rect" title=" " alt="" coords="101,80,166,107"/>
<area shape="poly" title=" " alt="" coords="136,33,136,64,131,64,131,33"/>
<area shape="rect" title=" " alt="" coords="189,80,254,107"/>
<area shape="poly" title=" " alt="" coords="151,30,196,68,193,72,147,35"/>
</map>
</div>
</div>
<p><a href="base64_8h_source.html">Go to the source code of this file.</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:a273df8cdcb82e13d2f7639ac04bedb7d" id="r_a273df8cdcb82e13d2f7639ac04bedb7d"><td class="memItemLeft" align="right" valign="top">L8W8JWT_API int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a273df8cdcb82e13d2f7639ac04bedb7d">l8w8jwt_base64_encode</a> (int url, const uint8_t *data, size_t data_length, char **out, size_t *out_length)</td></tr>
<tr class="separator:a273df8cdcb82e13d2f7639ac04bedb7d"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a4b8805d162fe585fc9d428207f61ae07" id="r_a4b8805d162fe585fc9d428207f61ae07"><td class="memItemLeft" align="right" valign="top">L8W8JWT_API int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a4b8805d162fe585fc9d428207f61ae07">l8w8jwt_base64_decode</a> (int url, const char *data, size_t data_length, uint8_t **out, size_t *out_length)</td></tr>
<tr class="separator:a4b8805d162fe585fc9d428207f61ae07"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Base-64 encode and decode strings/bytes. </p>
<dl class="section author"><dt>Author</dt><dd>Raphael Beck </dd></dl>
<dl class="section warning"><dt>Warning</dt><dd>The caller is responsible for freeing the returned buffers! </dd></dl>
<p>Pass <code>true</code> as first parameter if you want to use base64url encoding instead of base64. </p><dl class="section see"><dt>See also</dt><dd><a href="https://en.wikipedia.org/wiki/Base64#URL_applications">https://en.wikipedia.org/wiki/Base64#URL_applications</a> </dd></dl>
</div><h2 class="groupheader">Function Documentation</h2>
<a id="a4b8805d162fe585fc9d428207f61ae07" name="a4b8805d162fe585fc9d428207f61ae07"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a4b8805d162fe585fc9d428207f61ae07">&#9670;&#160;</a></span>l8w8jwt_base64_decode()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">L8W8JWT_API int l8w8jwt_base64_decode </td>
          <td>(</td>
          <td class="paramtype">int</td>          <td class="paramname"><span class="paramname"><em>url</em>, </span></td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const char *</td>          <td class="paramname"><span class="paramname"><em>data</em>, </span></td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t</td>          <td class="paramname"><span class="paramname"><em>data_length</em>, </span></td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint8_t **</td>          <td class="paramname"><span class="paramname"><em>out</em>, </span></td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t *</td>          <td class="paramname"><span class="paramname"><em>out_length</em></span>&#160;)</td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Decodes a base-64 encoded string to an array of bytes. </p>
<dl class="section note"><dt>Note</dt><dd>The returned bytes buffer is NUL-terminated to allow usage as a C string. </dd>
<dd>
The NUL terminator is NOT included in the <code>out_length</code>. </dd>
<dd>
DO NOT FORGET to free the output buffer once you're done using it!</dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">url</td><td>Decode using base64url instead of base64? Set to <code>0</code> for <code>false</code>; anything else for <code>true</code>. </td></tr>
    <tr><td class="paramname">data</td><td>The base-64 encoded string to decode (obtained via <code><a class="el" href="#a273df8cdcb82e13d2f7639ac04bedb7d">l8w8jwt_base64_encode</a></code>). </td></tr>
    <tr><td class="paramname">data_length</td><td>The length of the string to decode. </td></tr>
    <tr><td class="paramname">out</td><td>Output where the decoded bytes should be written into (will be malloc'ed, so make sure to <code>free()</code> this as soon as you're done using it!). </td></tr>
    <tr><td class="paramname">out_length</td><td>Pointer to a <code>size_t</code> variable into which to write the output buffer's length.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Return code as defined in <a class="el" href="retcodes_8h.html" title="Macros for possible integer codes returned by the various l8w8jwt functions.">retcodes.h</a> </dd></dl>

</div>
</div>
<a id="a273df8cdcb82e13d2f7639ac04bedb7d" name="a273df8cdcb82e13d2f7639ac04bedb7d"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a273df8cdcb82e13d2f7639ac04bedb7d">&#9670;&#160;</a></span>l8w8jwt_base64_encode()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">L8W8JWT_API int l8w8jwt_base64_encode </td>
          <td>(</td>
          <td class="paramtype">int</td>          <td class="paramname"><span class="paramname"><em>url</em>, </span></td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const uint8_t *</td>          <td class="paramname"><span class="paramname"><em>data</em>, </span></td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t</td>          <td class="paramname"><span class="paramname"><em>data_length</em>, </span></td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">char **</td>          <td class="paramname"><span class="paramname"><em>out</em>, </span></td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">size_t *</td>          <td class="paramname"><span class="paramname"><em>out_length</em></span>&#160;)</td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Encodes a byte array to a base-64 string. </p>
<p>If you're encoding a string, don't include the NUL terminator (pass <code>strlen(data)</code> instead of the array's size to the <code>data_length</code> parameter). </p>
<dl class="section note"><dt>Note</dt><dd>The output buffer is NUL-terminated to make it easier to use as a C string. </dd>
<dd>
The NUL terminator is NOT included in the <code>out_length</code>. </dd>
<dd>
DO NOT FORGET to free the output buffer once you're done using it!</dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">url</td><td>base64url encode instead of base64? Set to <code>0</code> for <code>false</code>; anything else for <code>true</code>. </td></tr>
    <tr><td class="paramname">data</td><td>The data (array of bytes) to base-64 encode. </td></tr>
    <tr><td class="paramname">data_length</td><td>The length of the input data array (in case of a C string: array size - 1 in order to omit the NUL terminator). </td></tr>
    <tr><td class="paramname">out</td><td>Output where the base-64 encoded string should be written into (will be malloc'ed, so make sure to <code>free()</code> this as soon as you're done using it!). </td></tr>
    <tr><td class="paramname">out_length</td><td>Pointer to a <code>size_t</code> variable containing the length of the output buffer minus the NUL terminator.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Return code as defined in <a class="el" href="retcodes_8h.html" title="Macros for possible integer codes returned by the various l8w8jwt functions.">retcodes.h</a> </dd></dl>

</div>
</div>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.10.0
</small></address>
</body>
</html>
